home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / play / tracker_4_31.lzh / tracker / Arch / Sgi / audio.c next >
C/C++ Source or Header  |  1995-02-26  |  4KB  |  179 lines

  1. /* sgi/audio.c 
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: audio.c,v 4.7 1995/02/26 23:07:14 espie Exp espie $
  6.  * $Log: audio.c,v $
  7.  * Revision 4.7  1995/02/26  23:07:14  espie
  8.  * tsync.
  9.  *
  10.  * Revision 4.6  1995/02/23  22:41:45  espie
  11.  * Added # of bits.
  12.  *
  13.  * Revision 4.5  1995/02/23  17:03:14  espie
  14.  * Continuing changes for a standard file.
  15.  *
  16.  * Revision 4.4  1995/02/23  13:52:30  espie
  17.  * primary, secondary -> primary+secondary, primary-secondary
  18.  * strike out 2 multiplications out of 4 !
  19.  *
  20.  * Revision 4.3  1995/02/21  17:57:55  espie
  21.  * Internal problem: RCS not working.
  22.  *
  23.  * Revision 4.2  1995/02/01  16:43:47  espie
  24.  * 23 bit samples.
  25.  *
  26.  * Revision 4.0  1994/01/11  18:01:04  espie
  27.  * Changed name.
  28.  *
  29.  * Revision 3.8  1993/12/04  16:12:50  espie
  30.  * BOOL -> boolean.
  31.  *
  32.  * Revision 3.7  1993/11/11  20:00:03  espie
  33.  * Amiga support.
  34.  *
  35.  * Revision 3.6  1993/07/14  16:33:41  espie
  36.  * Added stuff.
  37.  *
  38.  * Revision 3.5  1993/05/09  14:06:03  espie
  39.  * Corrected mix problem.
  40.  *
  41.  * Revision 3.4  1992/11/27  10:29:00  espie
  42.  * General cleanup
  43.  *
  44.  * Revision 3.3  1992/11/24  10:51:19  espie
  45.  * Added pseudo discardbuffer.
  46.  *
  47.  * Revision 3.2  1992/11/22  17:20:01  espie
  48.  * Checks for finetune ?
  49.  *
  50.  * Revision 3.1  1992/11/19  20:44:47  espie
  51.  * Protracker commands.
  52.  *
  53.  * Revision 3.0  1992/11/18  16:08:05  espie
  54.  * New release.
  55.  *
  56.  * Revision 2.11  1992/11/17  15:38:00  espie
  57.  * Dummy discard_buffer()
  58.  * Changed sync_audio value again.
  59.  * Added synchro for dump.
  60.  * Bug fix: must ask new frequency after we tried to set it to get it
  61.  * rounded up.
  62.  * Added stereo option (kind of).
  63.  * Separated mix/stereo stuff.
  64.  * Checked buffer size.
  65.  * Added possibility to get back to MONO for the sgi.
  66.  * Added stereo capabilities to the indigo version.
  67.  * Ask the frequency to the audio device.
  68.  * Corrected bug: when closing audio,
  69.  * we now wait for the samples queue to be empty.
  70.  */
  71.  
  72. #include <audio.h>
  73. #include "defs.h"
  74. #include "extern.h"
  75.  
  76. #define DEFAULT_BUFFERS
  77. #define DEFAULT_SET_MIX
  78. #define NEW_OUTPUT_SAMPLES_AWARE
  79.  
  80. #include "Arch/common.c"
  81.  
  82. XT int sginap(long ticks);
  83.      
  84. ID("$Id: audio.c,v 4.7 1995/02/26 23:07:14 espie Exp espie $")
  85.  
  86. LOCAL int number;
  87.  
  88. LOCAL ALport audio;
  89. LOCAL ALconfig config;
  90.  
  91. LOCAL int donotwait = FALSE;
  92. LOCAL long chpars[] = {AL_OUTPUT_RATE, 0};
  93.  
  94.  
  95. int open_audio(f, s)
  96. int f, s;
  97.    {
  98.  
  99.     donotwait = FALSE;
  100.    chpars[1] = f;
  101.    if (f != 0)
  102.         ALsetparams(AL_DEFAULT_DEVICE, chpars, 2);
  103.    ALgetparams(AL_DEFAULT_DEVICE, chpars, 2);
  104.    config = ALnewconfig();
  105.    stereo = s;
  106.    if (stereo)
  107.         {
  108.       ALsetchannels(config, AL_STEREO);
  109.       number = 2;
  110.       }
  111.    else
  112.       {
  113.       ALsetchannels(config, AL_MONO);
  114.       number = 1;
  115.       }
  116.    ALsetwidth(config, AL_SAMPLE_16);
  117.    audio = ALopenport("soundtracker mono", "w", config);
  118.    idx = 0;
  119.    buffer16 = malloc(sizeof(signed short) * number * chpars[1]);
  120.    return chpars[1];
  121.    }
  122.  
  123. void set_synchro(s)
  124. int s;
  125.     {
  126.     tsync = s;
  127.     }
  128.  
  129. int update_frequency()
  130.     {
  131.     int oldfreq;
  132.  
  133.     oldfreq = chpars[1];
  134.     ALgetparams(AL_DEFAULT_DEVICE, chpars, 2);
  135.     if (chpars[1] != oldfreq)
  136.         {
  137.         buffer16 = realloc(buffer16, sizeof(signed short) * number * chpars[1]);
  138.         return chpars[1];
  139.         }
  140.     else
  141.         return 0;
  142.     }
  143.  
  144.  
  145. void output_samples(int left, int right, int n)
  146.     {
  147.     add_samples16(left, right, n);
  148.     }
  149.  
  150. void flush_buffer(void)
  151.    {
  152.    ALwritesamps(audio, buffer16, idx);
  153.     if (tsync)
  154.         while(ALgetfilled(audio) > idx * 10)
  155.             /* busy wait */
  156.             ;
  157.    idx = 0;
  158.    }
  159.  
  160. void discard_buffer(void)
  161.     {
  162.     donotwait = TRUE;
  163.     /* mostly not implemented, only working when using close_audio
  164.      * right after
  165.      */
  166.     }
  167.  
  168. void close_audio(void)
  169.    {
  170.     if (!donotwait)
  171.         {
  172.         while(ALgetfilled(audio) != 0)
  173.             sginap(1);
  174.         }
  175.    ALcloseport(audio);
  176.    ALfreeconfig(config);
  177.    free(buffer16);
  178.    }
  179.